﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using PTCapture.UserControls;
using System.IO;
using PTCapture.Support;

namespace PTCapture.Forms
{
    public partial class MainForm : Form
    {
        #region Controls

        /// <summary>
        /// Drag drop
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void lbImages_MouseDown(object sender, MouseEventArgs e)
        {
            if (lbImages.Items.Count == 0)
            {
                return;
            }

            int index = lbImages.IndexFromPoint(e.X, e.Y);

            if (index < 0)
            {
                return;
            }

            ListItem s = (ListItem)lbImages.Items[index];

            DragDropEffects dde = DoDragDrop(s, DragDropEffects.All);

            if (dde == DragDropEffects.All)
            {
                lbImages.Items.RemoveAt(index);
            }
        }

        #endregion

        #region Support

        /// <summary>
        /// Populate created images
        /// </summary>
        public void PopulateImages()
        {
            string[] files = Directory.GetFiles(GlobalVariables.ImagePath, "*.png");
            string[] splits = new string[] { "_FromVideo_" };

            lbImages.Items.Clear();
            for (int i = 0; i < files.Length; i++)
            {
                string[] partialName = files[i].Split(splits, StringSplitOptions.RemoveEmptyEntries);
                partialName[1] = partialName[1].Replace("Recording", "R");
                lbImages.Items.Add(new ListItem(partialName[1].Substring(0, partialName[1].Length - 4), files[i]));
            }
        }

        #endregion

        #region DelegateCallbacks

        /// <summary>
        /// Snapshot made exercise, call back to main form.
        /// </summary>
        /// <returns></returns>
        bool snapshotDrawer1_MadeExercise()
        {
            tcMain.SelectedIndex = 0;

            patients1.RebindAssignedExercises();
            patients1.SavePatientXML();
            patients1.RebindExercises();

            return true;
        }

        #endregion
    }
}
